﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_panel_Suabaiviet : System.Web.UI.Page
{
    BieumauDataContext db = new BieumauDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["login_admin"] == null)
        {
            Response.Redirect("Index.aspx");
        }
        if (!IsPostBack)
        {
            load_bt();
            load_gt();
        }
    }
    /// <summary>
    /// load bai viet gioi thieu
    /// </summary>
    public void load_gt()
        {
            if (Request.QueryString["idgt"] != null)
            {
                int idgt = Convert.ToInt32(Request.QueryString["idgt"]);
                tblGioiThieu gt = db.tblGioiThieus.Single(p => p.IDGioiThieu == idgt);
                txttieude.Text = gt.TieuDe;
                FCK_gioithieu.Value = gt.NoiDung;
            }
            
        }
    /// <summary>
    /// load ban tin
    /// </summary>
    public void load_bt()
    {
        if (Request.QueryString["idbt"] != null)
        {
            int idtin = Convert.ToInt32(Request.QueryString["idbt"]);
            tblBanTin bt = db.tblBanTins.Single(p => p.IDTin == idtin);
            txtbantin.Text = bt.TieuDe;
            FCK_bantin.Value = bt.NoiDung;
            txtnoidungtomtat.Text = bt.NoiDungTomTat;
        }

    }
    /// <summary>
    /// cập nhật bản tin
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btncapnhatBT(object sender, EventArgs e)
    {
        int idtin = Convert.ToInt32(Request.QueryString["idbt"].ToString());
        tblBanTin vb = db.tblBanTins.Single(p => p.IDTin == idtin);
        vb.TieuDe = txtbantin.Text;
        vb.NoiDungTomTat = txtnoidungtomtat.Text;
        vb.NoiDung = FCK_bantin.Value;
        db.SubmitChanges();
        Response.Redirect("BanTin.aspx");
    }
    /// <summary>
    /// cập nhật bài giới thiệu
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btncapnhatGT(object sender, EventArgs e)
    {
        int idgt = Convert.ToInt32(Request.QueryString["idgt"].ToString());
        tblGioiThieu vb = db.tblGioiThieus.Single(p => p.IDGioiThieu == idgt);
        vb.TieuDe = txttieude.Text;
        vb.NoiDung = FCK_gioithieu.Value;
        db.SubmitChanges();
        Response.Redirect("BanTin.aspx");
    }
   
}